﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;

public partial class Master_Admin_photolist : Admin_BasePage
{

    protected UserPhoto UphotoBll = new UserPhoto();
    protected Users U = new Users();
    protected int Classid = 0;
    protected string wherestr = " isdel=0 ";
    protected int IndexPage = 1;
    protected string Action = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();

        if (Request["Classid"] != null)
        {
            Classid = StringHelper.isNumber_int(Request["Classid"].ToString());
        }
        if (Request["Action"] != null)
        {
            Action = Request["Action"].ToString();
        }
        if (Action == "check")
        {
            wherestr += " and  ischeck=0  ";
        }
        if (Action == "my")
        {
            wherestr += " and  CreateId=0  ";
        }
        if (Classid > 0)
        {
            wherestr += " and  ClassID=" + Classid.ToString();
        }



        if (!Page.IsPostBack)
        {
            bind();

        }





    }
    protected string GetClassNameAll()
    {
        string Result = "";

        DataTable dt = UphotoBll.GetDataTable_Class("");
        foreach (DataRow dr in dt.Rows)
        {
            if (Classid == StringHelper.isNumber_int(dr["id"].ToString()))
            {
                Result += "<a href=\"Admin_photolist.aspx?Classid=" + dr["Id"].ToString() + "\"><span style='color:Red;'>" + dr["ClassName"].ToString() + "</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;";
            }
            else
            {
                Result += "<a href=\"Admin_photolist.aspx?Classid=" + dr["Id"].ToString() + "\">" + dr["ClassName"].ToString() + "</a>&nbsp;&nbsp;|&nbsp;&nbsp;";
            }
        }
        return Result;
    }
    protected string GetClassName(string id)
    {
        string Result = "";
        Result = UphotoBll.UserPhoto_Class_Column<string>("ClassName", StringHelper.isNumber_int(id));
        return Result;
    }
    protected string GetUserName(string id)
    {
        string Result = "";
        Result = UphotoBll.UserPhoto_Class_Column<string>("ClassName", StringHelper.isNumber_int(id));
        return Result;
    }



    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bind();
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        UserPhoto_Model UphotoModel = new UserPhoto_Model();
        string CommandName = e.CommandName.ToString();
        int CommandID = StringHelper.isNumber_int(e.CommandArgument.ToString());
        UphotoModel.Id = CommandID;
        switch (CommandName)
        {
            case "CloseCheck":
                UphotoModel.IsCheck = 0;
                UphotoBll.UpdateCheck(UphotoModel);
                break;
            case "CheckOk":

                UphotoModel.IsCheck = 1;
                UphotoBll.UpdateCheck(UphotoModel);
                break;
            case "Delinfo":
                UserPhoto_Model MdDel = UphotoBll.GetModel(CommandID);
                if (UphotoBll.delete(CommandID) > 0)
                {
                    StringHelper.delFile(MdDel.PhotoUrl);
                }
                break;

        }
        Response.Redirect("Admin_photolist.aspx?page=" + IndexPage + "&classid=" + Classid.ToString() + "&Action=" + Action);
        Response.End();
    }
    protected void bind()
    {
        DataTable dt = UphotoBll.GetDataTable(wherestr);
        this.AspNetPager1.PageSize = 15;
        Pager p = new Pager();
        p.PageIndex = IndexPage;
        p.Ident = "id";
        p.Obj = Repeater1;
        p.Orderfld = "Addtime";
        p.OrderType = "desc";
        p.PageIndex = this.AspNetPager1.CurrentPageIndex;
        p.PageSize = this.AspNetPager1.PageSize;
        p.TableName = "UserPhoto";
        p.WhereStr = wherestr;
        p.ControlBind();
        this.AspNetPager1.RecordCount = p.recordcount();
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            LinkButton linkbtn = e.Item.FindControl("LinkButton1") as LinkButton;
            if (drv["ischeck"].ToString() == "1")
            {
                linkbtn.Text = "取消审核";
                linkbtn.CommandName = "CloseCheck";
            }
            else
            {
                linkbtn.Text = "<span style='color:Red;'>通过审核</span>";
                linkbtn.CommandName = "CheckOk";
            }



        }


        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (Repeater1.Items.Count == 0)//显示的数据项为0 既是没有数据
            {
                ((Panel)e.Item.FindControl("pl_nothing")).Visible = true;
                AspNetPager1.Visible = false;
            }
        }

    }
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        string PhotoID = "";
        if (Request["PhotoID"] != null)
        {
            PhotoID = Request["PhotoID"].ToString();
        }
        if (PhotoID == "")
        {
            ShowMsgBack("参数传递错误!");
            Response.End();
        }
        string[] IdArry = StringHelper.SplitString(PhotoID, ",");

        foreach (string str in IdArry)
        {
            if (StringHelper.strNull(str) == "") { break; }
            if (StringHelper.isNumber_int(str) <= 0) { break; }
            UserPhoto_Model Uphoto_model = UphotoBll.GetModel(StringHelper.isNumber_int(str));

            if (UphotoBll.delete(StringHelper.isNumber_int(str)) > 0)
            {
                StringHelper.delFile(Uphoto_model.PhotoUrl);
            }
        }
        Response.Redirect("Admin_photolist.aspx?page=" + IndexPage + "&classid=" + Classid.ToString() + "&Action=" + Action);
        Response.End();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        string PhotoID = "";
        if (Request["PhotoID"] != null)
        {
            PhotoID = Request["PhotoID"].ToString();
        }
        if (PhotoID == "")
        {
            ShowMsgBack("参数传递错误!");
            Response.End();
        }
        string[] IdArry = StringHelper.SplitString(PhotoID, ",");

        foreach (string str in IdArry)
        {
            if (StringHelper.strNull(str) == "") { break; }
            if (StringHelper.isNumber_int(str) <= 0) { break; }
            UserPhoto_Model Uphoto_model = UphotoBll.GetModel(StringHelper.isNumber_int(str));
            Uphoto_model.IsCheck = 1;
            UphotoBll.UpdateCheck(Uphoto_model);
        }
        Response.Redirect("Admin_photolist.aspx?page=" + IndexPage + "&classid=" + Classid.ToString() + "&Action=" + Action);
        Response.End();
    }
}
